package com.jz.yanshe.ui;

import android.widget.EditText;
import android.widget.Toast;

import com.jz.yanshe.base.BaseActivity;
import com.jz.yanshe.eventbus.OrderRefreshEvent;
import com.jz.yanshe.util.PreferencesHelper;

import com.jz.yanshe.R;
import com.jz.jd.rest.business.RestProxy;
import com.jz.jd.rest.exception.BusinessException;
import com.jz.jd.rest.response.BaseResponse;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2018/3/26.
 */

public class RefundActivity extends BaseActivity {

    @BindView(R.id.tv_express_no)
    EditText tv_express_no;

    @BindView(R.id.tv_express_name)
    EditText tv_express_name;

    @BindView(R.id.edt_remark)
            EditText edt_remark;

    String id;

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {
            id = getIntent().getStringExtra("id");
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_refund;
    }

    @OnClick(R.id.btn_confirm)
    void btn_confirm(){
        refund(id,tv_express_no.getText().toString(),tv_express_name.getText().toString(),edt_remark.getText().toString());
    }

    private void refund(String order_id, String express_code, String express_name,String remark) {
        RestProxy.getInstance().refund(PreferencesHelper.getInstance().getString(this, "token"), order_id, express_code, express_name, remark,new Observer<BaseResponse>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(BaseResponse baseResponse) {
                Toast.makeText(RefundActivity.this, baseResponse.message, Toast.LENGTH_SHORT).show();
                EventBus.getDefault().postSticky(new OrderRefreshEvent("1"));
                finish();
            }

            @Override
            public void onError(Throwable e) {
                if (e instanceof BusinessException) {
                    Toast.makeText(RefundActivity.this, ((BusinessException) e).errorDescription, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onComplete() {

            }
        });
    }

}
